package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.SkuInfo;
import com.atguigu.gmall.product.service.SkuManageService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.ReactiveSubscription;
import org.springframework.web.bind.annotation.*;

/**
 * @author: atguigu
 * @create: 2023-09-01 11:43
 */
@RestController
@RequestMapping("/admin/product")
public class SkuManageController {


    @Autowired
    private SkuManageService skuManageService;


    /**
     * 保存sku商品
     *
     * @param skuInfo
     * @return
     */
    @ApiOperation("保存SKU商品")
    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo) {
        skuManageService.saveSkuInfo(skuInfo);
        return Result.ok();
    }


    /**
     * 分页查询商品SKU列表
     *
     * @param page
     * @param limit
     * @param category3Id
     * @return
     */
    @ApiOperation("分页查询商品SKU列表")
    @GetMapping("/list/{page}/{limit}")
    public Result getSkuList(@PathVariable("page") int page, @PathVariable("limit") int limit, @RequestParam("category3Id") Long category3Id) {
        Page<SkuInfo> skuInfoPage = new Page<>(page, limit);
        skuInfoPage = skuManageService.getSkuList(skuInfoPage, category3Id);
        return Result.ok(skuInfoPage);
    }

    /**
     * 上架SKU商品
     * @param skuId
     * @return
     */
    @ApiOperation("上架SKU商品")
    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable("skuId") Long skuId){
        skuManageService.onSale(skuId);
        return Result.ok();
    }

    /**
     * 下架SKU商品
     * @param skuId
     * @return
     */
    @ApiOperation("下架SKU商品")
    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){
        skuManageService.cancelSale(skuId);
        return Result.ok();
    }
}
